Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the logo image in the "ui" UI example #7894

Merged
merged 9 commits into from
Jun 12, 2023

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Mar 4, 2023

Objective

The AccessKit PR removed the loading of the image logo from the UI example.
It also added some alt text with TextStyle::default() as a child of the logo image node.

If you give an image node a child, then its size is no longer determined by the measurefunc that preserves its aspect ratio. Instead, its width and height are determined by the constraints set on the node and the size of the contents of the node. In this case, the image node is set to have a width of 500 with no constraints on its height. So it looks at its child node to determine what height it should take. Because the child has TextStyle::default it allocates no space for the text, the height of the image node is set to zero and the logo isn't drawn.

Fixes #8805

Solution

Load the image, and set min_size and max_size constraints of 500 by 125 pixels.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples A-Accessibility A problem that prevents users with disabilities from using Bevy A-UI Graphical user interfaces, styles, layouts, and widgets labels Mar 4, 2023
@alice-i-cecile
Copy link
Member

Ping @ndarilek for review.

@alice-i-cecile
Copy link
Member

Looks like the alt text remains in the current version of this PR?

@ndarilek
Copy link
Contributor

ndarilek commented Mar 4, 2023

I do of course want the image back, but I'm not OK with removing the alt text.

I'm not sure what the intent was here.

I'd like to clarify that. Are you unsure what alt text is, unclear on its utility, or something else? Genuinely not trying to be sarcastic, but I'd rather fix this than remove accessibility, if only so our examples do a good job of it.

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Mar 4, 2023

I understand what alt text is but I haven't looked at the AccessKit pr before today and I don't understand the intent behind this implementation.

With TextStyle::default() no text is drawn, and no image is drawn because the zero height of the text node is inherited by the parent image node as well because of how the measurefunc works.

@ndarilek
Copy link
Contributor

ndarilek commented Mar 4, 2023

Got it.

For context, I'm a blind screen reader user. When I explore this UI with NVDA (my screen reader) running, I can find the Bevy logo when reviewing screen content, and am told that it is the Bevy logo. Admittedly that isn't super useful in this toy example, but it does at least display what I'd like us to consider a best practice, and is useful for discussing screens and UIs in an inclusive way (I.e. someone saying "X is true on the screen with the Bevy logo" might not mean anything to me otherwise.)

It's OK if the text isn't displayed--at least, it is until we've got a better UI that displays alt text similar to how HTML does. For the moment I needed some way to attach the alt text to an image, and making it a child node seemed to accomplish that. Ideally in the future we'll have a more fleshed-out UI component that includes alt text/widget descriptions directly and unambiguously.

I can't of course speak to how this PR appears visually but I've verified that the UI example still presents alt text correctly. Apologies for breaking the image, and thanks for the fix!

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Mar 4, 2023

I've only been looking at the accessibility module for a few minutes so this might be nonsense, but would a change something like this be acceptable:

#[derive(Component)]
pub struct AltText(pub String);

fn image_changed(
    mut commands: Commands,
    mut query: Query<
        (Entity, &AltText, Option<&mut AccessibilityNode>),
        (Changed<UiImage>, Without<Button>),
    >,
) {
    for (entity, alt_text, accessible) in &mut query {
        let name = alt_text.0.clone().into_boxed_str();
        if let Some(mut accessible) = accessible {
            accessible.set_role(Role::Image);
            accessible.set_name(name);
        } else {
            let mut node = NodeBuilder::new(Role::Image);
            node.set_name(name);
            commands
                .entity(entity)
                .insert(AccessibilityNode::from(node));
        }
    }
}

And we would add the AltText component to the ImageBundle.

@alice-i-cecile
Copy link
Member

This sort of design makes sense to me: you should be able to read both explicit alt text and text from Text components.

@ickshonpe
Copy link
Contributor Author

For the moment, I've constrained the Image to a fixed size so it will display correctly with the text as a child.

@ndarilek
Copy link
Contributor

ndarilek commented Mar 4, 2023

I'm absolutely in favor of adding more accessibility-specific components and fields, but I'd like to be intentional about it as part of comprehensive UI overhauls rather than creating individual, separate components. I made that mistake by introducing a Label component, which in retrospect I probably should have just handled with a custom NodeBuilder.

All that is to say, if we can fix this without introducing a new component, I'd be more in favor of that, particularly with a 0.10 release imminent.

bors bot pushed a commit to bevyengine/bevy-website that referenced this pull request Mar 4, 2023
🎉 

I've deliberately left out a full code example for now. This is a) almost certain to change by the time 0.11 comes b) is quite clunky c) requires some [trickery](bevyengine/bevy#7894) to get alt text displaying properly.

I care a lot about making this better, so stay tuned.
@ickshonpe
Copy link
Contributor Author

ickshonpe commented Mar 6, 2023

Had some further thoughts about this:

  • Perhaps another option for alt-text might be for assets to have an optional description string? Then users could add a description to media assets like images and sound effects that could be used in their place when necessary. A user would add an ImageBundle like now and if the player of the game is using a screen reader the image systems could automatically retrieve the description string instead of an image. That might also be useful for prototyping and debugging, not just accessibility.

  • I've replaced the ImageBundle with a NodeBundle that has a white background color and a UiImage component, and added a comment explaining why. I think this is okay and allows for the example to be included in 0.10 if there isn't time to find another solution for alt-text. It provides a demonstration of how to spawn a UI node with an image and children without errors.

@ickshonpe ickshonpe mentioned this pull request Mar 6, 2023
@ickshonpe ickshonpe changed the title Fix UI example logo Fix the logo image in the UI example Mar 6, 2023
@ickshonpe ickshonpe changed the title Fix the logo image in the UI example Fix the logo image in the "ui" UI example Mar 6, 2023
@nicopap nicopap added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 10, 2023
Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You say

I've replaced the ImageBundle with a NodeBundle that has a white background color and a UiImage component, and added a comment explaining why. I think this is okay and allows for the example to be included in 0.10 if there isn't time to find another solution for alt-text. It provides a demonstration of how to spawn a UI node with an image and children without errors.

But I don't see a comment explaining it.

I assume it's because the text is white and therefor invisible on white background? Not too hot on that, what made you chose that over using Visibility::Hidden?

@nicopap nicopap removed the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 10, 2023
@ickshonpe
Copy link
Contributor Author

ickshonpe commented Jun 10, 2023

You say

I've replaced the ImageBundle with a NodeBundle that has a white background color and a UiImage component, and added a comment explaining why. I think this is okay and allows for the example to be included in 0.10 if there isn't time to find another solution for alt-text. It provides a demonstration of how to spawn a UI node with an image and children without errors.

But I don't see a comment explaining it.

I'm not sure what to happened to the comment, perhaps I forgot to add it to the commit. I'll fix it.

I assume it's because the text is white and therefor invisible on white background? Not too hot on that, what made you chose
that over using Visibility::Hidden?

This PR was written before the change that added a default font and TextStyle::default() wouldn't draw any text.

A NodeBundle can display an image as long as you give it a UiImage component but you to have set a BackgroundColor as NodeBundle is transparent by default.

@nicopap nicopap added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 11, 2023
@nicopap
Copy link
Contributor

nicopap commented Jun 11, 2023

Could you add a "fixes #8805" in the PR description?

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 12, 2023
Merged via the queue into bevyengine:main with commit 6fc619d Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Accessibility A problem that prevents users with disabilities from using Bevy A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bevy logo has disapeared from the ui.rs example
4 participants